package ngat.oss.simulation;

import java.util.*;

import ngat.phase2.*;

/** Basic implementation of a SelectionHeuristic. Chooses a group at random.
 */ 
public class RandomSelectionHeuristic implements SelectionHeuristic {

    /** Random seed (v.large).*/
    private int seed;

    public RandomSelectionHeuristic(int seed) {
	this.seed = seed;
    }

    /** Returns a random group from the supplied candidate metrics or null
     * if no suitable group can be found.
     */
    public Metric getBestGroup(List candidates) {

	int cs = candidates.size();
	if (cs== 0)
	    return null;
	
	// the selection number
	int ds = (int)(Math.random()*(double)seed);
	int is = ds % cs;
	
	Metric best = (Metric)candidates.get(is);
	best.generator = "RandomSelectionHeuristic";

	if (best.group == null)
	    return null;

	return best;

    }

    /** Returns the probability of the test metric being selected from the supplied candidate metrics.
     * The test metric must not already be present in the candidate list.
     */
    public double getSelectionProbability(List candidates, Metric test) {
	return 1.0;
    }

}
